function imgError(obj){
	$(obj).attr('style','background-color:#29aae3;border-radius: 5px;');
	$(obj).attr('src','../img/app/appIconDefalut.png');
}

function clickQrcode(){
//	$('.qr-btn').click();
	if(_phoneType=="Android"){
		window.jump.QRCode(); 
	}else if(_phoneType=="Ios"){
		window.webkit.messageHandlers.useQRCode.postMessage({body: 'useQRCode'});
	}else{
		alert('暂时不支持此功能!');
	}
	return false;
}

(function() {
	
	$(document).ready(function() {
		getMenu();
		Qrcode.init($('[node-type=qr-btn]'));
	});

	function getMenu(){
		var url = window.rootPath + '/ui/Application/getMenu';
		jQuery.ajax({
			url : encodeURI(url),
			cache : false,
			type : "get",
			data : "",
			dataType : "json",
			contentType : 'application/json;charset=utf-8',// 解决返回数据中的中文乱码问题
			success : function(data) {
				var menus = data.menus;
				setMenu(menus);
			}
		})
	}
	
	function setMenu(data){
		var divW = $('.menu').outerWidth();
//		var w = 'calc(('+divW+'px - 1.2em) /  )';
//		alert(fontSize);
		var content ='<ul>';
		content += '<li><a href="#" class="menuClick"><div><img src="../img/app/积分规则.png"/></div><span>积分规则</span></a></li>';
		content += '<li><a href="#" class="menuClick"><div><img src="../img/app/卫生间.png"/></div><span>寻找厕所</span></a></li>';
		content += '<li><a href="#" class="menuClick"><div><img src="../img/app/停车位.png"/></div><span>寻找车位</span></a></li>';
		for (var i = 0; i < data.length; i++) {
			var url = "";
			if(data[i].mobile!=undefined && data[i].mobile=="true"){
				if(data[i].target.indexOf("?") != -1){
					url=window.rootPath+data[i].target+"&device=mobile&identify=";
				}else{
					url=window.rootPath+data[i].target+"?device=mobile&identify=";
				}
			}
			
			if(data[i].target.indexOf('#') > -1){
				url = "#";
				content += '<li><a href="'+url+'" onclick="clickQrcode();" data-ajax="false"><div><img src="../img/app/'+data[i].icon+'.png" onerror="imgError(this)"/></div><span>'+data[i].moduleName+'</span></a></li>';
			}else{
				content += '<li><a href="'+url+'" data-ajax="false" class="menuClick"><div><img src="../img/app/'+data[i].icon+'.png" onerror="imgError(this)"/></div><span>'+data[i].moduleName+'</span></a></li>';
			}
		}
		content +='</ul>';
		jQuery('.menu').append(content);
	}
})();

